<script setup>
import { Search, Edit, Delete as DeleteView } from '@element-plus/icons-vue';

const form = reactive({
  aaa: '',
  bbb: '',
  ccc: '',
  ddd: '',
  eee: '',
  fff: '',
});
const aaaOptions = ref([
  {
    label: 'Option1',
    value: 'Option1',
  },
]);
const fffOptions = ref([
  {
    label: 'Option1',
    value: 'Option1',
  },
]);
const operateOptions = ref([
  {
    label: 'Option1',
    value: 'Option1',
  },
  {
    label: 'Option2',
    value: 'Option2',
  },
  {
    label: 'Option3',
    value: 'Option3',
  },
  {
    label: 'Option4',
    value: 'Option4',
  },
]);
const rules = ref({
  aaa: [
    {
      required: true,
      message: '请选择审计事项',
      trigger: ['blur', 'change'],
    },
  ],
  bbb: [
    {
      required: true,
      message: '请输入审计要点内容',
      trigger: 'blur',
    },
  ],
  ccc: [
    {
      required: true,
      message: '请输入查证思路',
      trigger: 'blur',
    },
  ],
});
const isEdit = ref(false);
const cardList = reactive([
  {
    id: '1',
    aaa: '减税降费优惠政策',
    operateAaa: '111',
    ccc: '工程建设项目是否有效运动国家减税降费优惠政策，各类合同是否及时按国家调整增值税税率执行，有无税率多签少技的行为2222222',
  },
  {
    id: '2',
    aaa: '减税降费优惠政策',
    operateAaa: '111',
    ccc: '工程建设项目是否有效运动国家减税降费优惠政策，各类合同是否及时按国家调整增值税税率执行，有无税率多签少技的行为',
  },
]);

const handleAdd = () => {
  isEdit.value = true;
};
const handleSave = () => {
  cardList.push({
    id: '3',
    aaa: form.aaa,
    operateAaa: form.fff,
    ccc: form.ccc,
  });
  isEdit.value = false;
};
const handleCancel = () => {
  isEdit.value = false;
};
const handleEdit = () => {
  isEdit.value = true;
};
const handleDel = (id) => {
  const index = cardList.findIndex(item => item.id === id);
  if (index !== -1) {
    cardList.splice(index, 1);
  }
};
</script>

<template>
  <div class="create-important-audit-content">
    <div class="title">
      <label class="title_label">审计内容</label>
      <el-button class="title__btn" type="primary" @click="handleAdd">新增要点</el-button>
    </div>
    <div class="main-empty" v-if="cardList.length < 1 && !isEdit">
      <div class="empty__container">
        <picture>
          <source srcset="@/assets/images/project-control/implementation-plan-empty.webp" type="image/webp">
          <source srcset="@/assets/images/project-control/implementation-plan-empty.png" type="image/png">
          <img
            src="@/assets/project-control/implementation-plan-empty.png"
            class="container__img"
          >
        </picture>
        <span class="container-prompt">
          目前暂无需展示内容，选择具体事项或点击 <span class="prompt--light">新增要点</span> 创建
        </span>
      </div>
    </div>
    <div class="main" v-else>
      <el-input
        v-if="cardList.length > 0"
        class="search-input"
        placeholder="搜索事项名称"
        :suffix-icon="Search"
      />
      <el-scrollbar :height="690">
        <div class="form" v-if="isEdit">
          <div class="form__title">
            <label class="title__label">新建要点</label>
            <div class="title__operate">
              <el-button type="primary" @click="handleSave">创建</el-button>
              <el-button @click="handleCancel">取消</el-button>
            </div>
          </div>
          <el-form
            class="form__content"
            :model="form"
            :rules="rules"
            label-width="90px"
          >
            <el-form-item label="审计事项" prop="aaa">
              <el-select v-model="form.aaa" class="content-select" placeholder="请选择审计事项" clearable>
                <el-option :label="opt.label" :value="opt.value" v-for="opt in aaaOptions" :key="opt.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="审计要点" prop="bbb">
              <el-input type="textarea" v-model="form.bbb" placeholder="请输入审计要点内容" :rows="3"></el-input>
            </el-form-item>
            <el-form-item label="查证思路" prop="ccc">
              <el-input type="textarea" v-model="form.ccc" placeholder="请输入查证思路" :rows="3"></el-input>
            </el-form-item>
            <el-form-item label="查证资料" prop="ddd">
              <el-input type="textarea" v-model="form.ddd" placeholder="请输入查证资料" :rows="3"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="eee">
              <el-input type="textarea" v-model="form.eee" placeholder="请输入备注" :rows="3"></el-input>
            </el-form-item>
            <el-form-item label="人员分工" prop="fff">
              <el-select v-model="form.fff" class="content-select" placeholder="请选择工作分工" clearable>
                <el-option :label="opt.label" :value="opt.value" v-for="opt in fffOptions" :key="opt.value"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="card" v-for="card in cardList" :key="card.id">
          <div class="card__content">
            <label class="content__label">{{ card.aaa }}</label>
            <label class="content__describe" :title="card.ccc">查证思路：{{ card.ccc }}</label>
          </div>
          <div class="card__operate">
            <el-select
              v-model="card.operateAaa"
              multiple
              collapse-tags
              collapse-tags-tooltip
              clearable
              class="operate-select"
              placeholder="请选择工作人员"
            >
              <el-option
                :label="opt.label"
                :value="opt.value" v-for="opt in operateOptions"
                :key="opt.value"></el-option>
            </el-select>
            <el-link type="primary" :underline="false" @click="handleEdit">
              编辑<el-icon class="el-icon--right"><edit /></el-icon>
            </el-link>
            <el-link type="primary" :underline="false" @click="handleDel(card.id)">
              删除<el-icon class="el-icon--right"><delete-view /></el-icon>
            </el-link>
          </div>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import '@/assets/style/common.scss';

.create-important-audit-content {
  width: 1284px;
  height: 794px;
  background: #FFF;
  border-radius: 4px;
  border: 1px solid #D9DCE4;

  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
    background: #F6F8FA;
    border-radius: 4px 4px 0px 0px;

    .title_label {
      height: 17px;
      font-size: 14px;
      color: #25292C;
      line-height: 17px;
      margin-left: 16px;
    }

    .title__btn {
      margin-right: 16px;
    }
  }

  .main-empty {
    .empty__container {
      display: flex;
      align-items: center;
      flex-direction: column;
      margin-top: 289px;

      .container__img {
        width: 100px;
        height: 94px;
        object-fit: cover;
      }
      .container-prompt {
        height: 20px;
        font-size: 14px;
        font-weight: 400;
        color: #989DA3;
        line-height: 20px;
        margin-top: 17px;

        .prompt--light {
          color: #2E72EF;
        }
      }
    }
  }

  .main {
    padding: 16px;

    .form {
      border-radius: 2px;
      border: 1px solid #D9DCE4;
      margin-top: 12px;

      .form__title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 64px;
        background: #F6F8FA;

        .title__label {
          height: 19px;
          font-size: 16px;
          font-weight: 500;
          color: #25292C;
          line-height: 19px;
          margin-left: 16px;
        }

        .title__operate {
          margin-right: 16px;
        }
      }

      .form__content {
        padding: 16px;

        .content-select {
          width: 100%;
        }
      }
    }
  }

  .card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    background: #F6F8FA;
    border-radius: 2px;
    border: 1px solid #D9DCE4;
    margin-top: 12px;
    padding: 0 16px;

    .card__content {
      display: flex;
      flex-direction: column;

      .content__label {
        height: 19px;
        font-size: 16px;
        font-weight: 500;
        color: #25292C;
        line-height: 19px;
      }

      .content__describe {
        @include ellipsis;

        width: 720px;
        height: 14px;
        font-size: 12px;
        font-weight: 400;
        color: #989DA3;
        line-height: 14px;
        margin-top: 11px;
      }
    }

    .card__operate {
      display: flex;
      gap: 19px;
    }
  }
}
</style>
